package cn.mumzone.pos.ui.adapter.warehouse;

import android.content.Context;
import android.view.View;

import cn.mumzone.basic.adapter.rv.CommonAdapter;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.basic.util.AppDateUtil;
import cn.mumzone.pos.AppConstants;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.InWarehouseItemEntity;
import cn.mumzone.pos.model.InventoryItemEntity;

/**
 * Created By Dlx
 * on 2019/9/25
 *
 */
public class ADA_WarehouseItem extends CommonAdapter<InWarehouseItemEntity> {

    private OnCardClickListener listener;

    public ADA_WarehouseItem(Context context) {
        super(context);
    }

    @Override
    protected int itemLayoutId() {
        return R.layout.item_in_warehouse_card;
    }

    public void setOnCardClickListener(OnCardClickListener listener) {
        this.listener = listener;
    }

    @Override
    protected void convert(ViewHolder holder, final InWarehouseItemEntity entity, int position) {

        holder.setText(R.id.tv_name, entity.getUserName());
        holder.setText(R.id.tv_status, getInStatus(entity.getInStatus()));

        holder.setText(R.id.tv_warehouse_id, entity.getInCode());

        holder.setText(R.id.tv_warehouse, entity.getWarehouseName());
        holder.setText(R.id.tv_type, getIntype(entity.getInType()));
        holder.setText(R.id.tv_num, entity.getInNum() + "");
        holder.setText(R.id.tv_date, AppDateUtil.getTimeStamp(entity.getCreateTime(), AppDateUtil.YYYY_MM_DD_HH_MM));

        holder.setOnClickListener(R.id.cv_root, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onCardClick(entity.getId());
                }
            }
        });

    }

    private String getIntype(int inType) {
        if (0 == inType)
            return "其他入库";
        if (1 == inType)
            return "收货入库";
        if (2 == inType)
            return "盘盈入库";
        if (4 == inType)
            return "退货入库";
        return "未知" + inType;
    }

    private String getInStatus(String inStatus) {
//        if ("0".equals(inStatus))
//            return "已审核";
//        if ("1".equals(inStatus))
//            return "待审核";
//        if ("2".equals(inStatus))
//            return "已退货";
//        if ("3".equals(inStatus))
//            return "已驳回";
        return "已生成";
    }

    public interface OnCardClickListener {
        void onCardClick(String id);
    }
}
